using System;
using System.Collections.Generic;
using IQIGame.Onigao.Framework;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace IQIGame.Onigao.GamePlay
{
    public class SkillJoystick : Joystick
    {
        [SerializeField] private GameObject mDragBg;
        [SerializeField] private Text mSkillID;
        [SerializeField] private Image mIcon;
        [SerializeField] private GameObject mIconMask;
        [SerializeField] private ExText mCd;
        [SerializeField] private ExImage mSpSlider;
        [SerializeField] private ExText mCurSpNum;

        public bool enable = true;

        protected override void TouchMove(Vector3 inputPosition)
        {
            if (!this.enable)
            {
                return;
            }
            base.TouchMove(inputPosition);
        }

        protected override void TouchUp()
        {
            base.TouchUp();
            if (this.mDragBg)
            {
                this.mDragBg.SetActive(false);
            }

            if (this.Stick)
            {
                this.Stick.gameObject.SetActive(false);
            }
        }

        protected override void TouchDown(PointerEventData eventData)
        {
            if (!this.enable)
            {
                return;
            }

            base.TouchDown(eventData);
            if (this.mDragBg)
            {
                this.mDragBg.SetActive(true);
            }

            if (this.Stick)
            {
                this.Stick.gameObject.SetActive(true);
            }
        }

        public void SetSkillIcon(Sprite icon, bool canUse, int cd)
        {
            if (this.mIcon)
            {
                this.mIcon.sprite = icon;
            }
            this.gameObject.SetActive(icon != null);
            this.enable = canUse;
            if (this.mIconMask)
            {
                this.mIconMask.SetActive(!canUse);
            }
            if (this.mCd)
            {                
                this.mCd.transform.parent.gameObject.SetActive(cd > 0);
                if (cd > 0)
                {
                    this.mCd.text = cd.ToString();
                }
            }
        }

        public void SetSetSkillIconWithSp(Sprite icon, bool canUse, int cd, float spRate, int curSp)
        {
            this.SetSkillIcon(icon, canUse, cd);
            if (this.mSpSlider)
            {
                this.mSpSlider.fillAmount = spRate;
            }
            if (this.mCurSpNum)
            {
                this.mCurSpNum.text = curSp.ToString();
            }
        }
    }
}